
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package heuristics;

/**
 *
 * @author ahmad
 */
import java.awt.*;
import java.awt.geom.*;
import java.util.ArrayList;
import java.util.Arrays;

public class BruteForceCoverage extends CoverageHeuristic {
    int bestCoverage;
    ArrayList<int[]> bestAssignments = new ArrayList<int[]>();
    
    public BruteForceCoverage(String file, int number_of_orientations) {
        super(file, number_of_orientations);
    }
    
    public BruteForceCoverage(ArrayList<Rectangle> obstacles, ArrayList<Point2D.Double> cameras, ArrayList<Point2D.Double> people, int number_of_orientations) {
        super(obstacles, cameras, people, number_of_orientations,false);
    }

    public int[] reassign() {
        computeSpotted();
        bestCoverage = 0;
        bestAssignments.clear();
        process(0, new int[number_of_cameras], new boolean[number_of_men]);
//        System.out.println(bestCoverage);
        return bestAssignments.get(0);
    }
    
    public void process(int cam, int[] assignment, boolean[] preCovered) {
        if (cam == cameras.size()) {
            int coverage = 0;
            for (boolean isCovered : preCovered) {
                if (isCovered) {
                    coverage++;
                }
            }
//            System.out.println(Arrays.toString(assignment) + " => " + coverage);
            if (coverage > bestCoverage) {
                bestCoverage = coverage;
                bestAssignments.clear();
            }
            if (coverage == bestCoverage) {
                bestAssignments.add(Arrays.copyOf(assignment, assignment.length));
            }
        } else {
            boolean[] covered = Arrays.copyOf(preCovered, preCovered.length);
            for (int i = 0; i < number_of_orientations; i++) {
                assignment[cam] = i;
                for (int j = 0; j < number_of_men; j++)
                    covered[j] = preCovered[j] || spotted[cam][0][i][j];
                process(cam + 1, assignment, covered);
            }
        }
    }

    @Override
    public String toString() {
        return "Brute Force";
    }
}
